home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / smaltalk.lha / smalltalk-1.1.1 / Magnitude.st < prev    next >
Text File  |  1991-09-12  |  2KB  |  92 lines

  1. "======================================================================
  2. |
  3. |   Magnitude Method Definitions
  4. |
  5.  ======================================================================"
  6.  
  7.  
  8. "======================================================================
  9. |
  10. | Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  11. | Written by Steve Byrne.
  12. |
  13. | This file is part of GNU Smalltalk.
  14. |
  15. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  16. | under the terms of the GNU General Public License as published by the Free
  17. | Software Foundation; either version 1, or (at your option) any later version.
  18. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  19. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  20. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  21. | details.
  22. | You should have received a copy of the GNU General Public License along with
  23. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  24. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  25. |
  26.  ======================================================================"
  27.  
  28.  
  29. "
  30. |     Change Log
  31. | ============================================================================
  32. | Author       Date       Change 
  33. | sbyrne     25 Apr 89      created.
  34. |
  35. "
  36.  
  37. Object subclass: #Magnitude
  38.        instanceVariableNames: ''
  39.        classVariableNames: ''
  40.        poolDictionaries: ''
  41.        category: nil.
  42.  
  43. Magnitude comment: 
  44. 'I am an abstract class.  My objects represent things that are discrete and 
  45. map to a number line.  My instances can be compared with < and >.' !
  46.  
  47. !Magnitude methodsFor: 'basic'!
  48.  
  49. "Relational operators.  '==', '~=', '~~' are inherited from Object"
  50.  
  51. = aMagnitude
  52.     self subclassResponsibility
  53. !
  54.  
  55. < aMagnitude
  56.     self subclassResponsibility
  57. !
  58.  
  59. > aMagnitude
  60.     self subclassResponsibility
  61. !
  62.  
  63. <= aMagnitude
  64.     ^(self < aMagnitude) | (self = aMagnitude)
  65. !
  66.  
  67. >= aMagnitude
  68.     ^(self > aMagnitude) | (self = aMagnitude)
  69. !!
  70.  
  71.  
  72.  
  73. !Magnitude methodsFor: 'misc methods'!
  74.  
  75. between: min and: max
  76.     "Returns true if object is inclusively between min and max."
  77.     ^(self >= min) and: [ self <= max ]
  78. !
  79.  
  80. min: aMagnitude
  81.     self < aMagnitude ifTrue: [ ^self ]
  82.                       ifFalse: [ ^aMagnitude ]
  83. !
  84.  
  85. max: aMagnitude
  86.     self > aMagnitude ifTrue: [ ^self ]
  87.                       ifFalse: [ ^aMagnitude ]
  88. !!
  89.  
  90.